﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Com.LongER.Business.ZBH001;
using Com.LongER.Framework.Utils;
using Com.LongER.UI;
using Com.LongER.Framework.Utils.LogUtils;

public partial class ZBH001 : ABasePage
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        
        //
        if (!this.Page.IsPostBack)
        {
            ///画面PGID，画面名设定
            #region
            Label lblPageId = (Label)Master.FindControl("lblPageId");
            lblPageId.Text = "ZBH001";

            Label lblPageName = (Label)Master.FindControl("lblPageName");
            lblPageName.Text = "订单一览查询画面";
            #endregion

            //清空画面中的输入框和表的值
            #region
            proc清空_Init("0");
            #endregion

            //取得下拉列表的值
            //this.setLists();           //Update by 黄  下拉框不要
        }

        //自动加载autocomplete
        #region
        this.txt订单状态.Text = this.hid订单状态.Value;
        this.txt客户.Text = this.hid客户.Value;
        this.txt付款方式.Text = this.hid付款方式.Value;
        this.txt品名.Text = this.hid品名.Value;
        this.txt所用车型.Text = this.hid所用车型.Value;
        this.txt起点省市.Text = this.hid起点省市.Value;
        this.txt发货地.Text = this.hid发货地.Value;
        this.txt终点省市.Text = this.hid终点省市.Value;
        this.txt送货地.Text = this.hid送货地.Value;
        #endregion
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn主菜单_Click(object sender, EventArgs e)
    {
        Response.Redirect("/LongER/ZAH003.aspx");
    }

    /// <summary>
    /// 取得下拉列表的值
    /// </summary>
    /// <returns></returns>
    private Boolean setLists()
    {
        ////通过调用Business下ZBH001类，获取通用主数据的所有值
        //CZBH001 instance = new CZBH001();
        //ZBH001DS.M_TONGYONGDataTable dt = instance.GetLists();

        ////由取得的通用主数据的数据集，取得[订单状态]的列表
        //var query = from data in dt.AsEnumerable()
        //            where data.CODE_CD == "DDZT"
        //            select data;

        //this.list订单状态.DataSource = query;
        //this.list订单状态.DataTextField = "CODE1_HANZI";
        //this.list订单状态.DataValueField = "KEY1";
        //this.list订单状态.DataBind();
        //this.list订单状态.SelectedIndex = 0;

        ////由取得的通用主数据的数据集，取得[付款方式]的列表
        //query = from data in dt.AsEnumerable()
        //        where data.CODE_CD == "FKFS"
        //        select data;

        //this.list付款方式.DataSource = query;
        //this.list付款方式.DataTextField = "CODE1_HANZI";
        //this.list付款方式.DataValueField = "KEY1";
        //this.list付款方式.DataBind();
        //this.list付款方式.SelectedIndex = 0;

        ////由取得的通用主数据的数据集，取得[车辆形态]的列表
        //query = from data in dt.AsEnumerable()
        //        where data.CODE_CD == "CLXT"
        //        select data;

        //this.listtxt所用车型.DataSource = query;
        //this.listtxt所用车型.DataTextField = "CODE1_HANZI";
        //this.listtxt所用车型.DataValueField = "KEY1";
        //this.listtxt所用车型.DataBind();
        //this.listtxt所用车型.SelectedIndex = 0;

        return true;
    }

    /// <summary>
    /// 点击[执行]按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn执行_Click(object sender, EventArgs e)
    {
        Dictionary<string, string> dic = new Dictionary<string, string>();
        dic.Add("ONO", this.txt订单号.Text.ToString());
        dic.Add("ZHUANGHUO_DATE", this.txt装货时间_Day.Text.ToString());
        dic.Add("XIEHUO_DATE", this.txt卸货时间_Day.Text.ToString());
        //
        if (this.hidPageNo.Value == string.Empty) this.hidPageNo.Value = "1";
        dic.Add("PAGE_NO", this.hidPageNo.Value);
       

        CZBH001 instance = new CZBH001();
    

        ZBH001DS.T_ORDERDataTable dt = instance.GetOrderList(dic);

        //标题行以外全部移除
        for (int i = this.tblList.Rows.Count-1; i >= 2; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

        if (dt != null)
            this.txt总件数.Text = dt.Count.ToString();

        int rowid = 0;
        //
        foreach (var dr in dt)
        {
            //创建新行
            TableRow row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }

            //选择
            TableCell cell = GetTableCell(width:30, rowspan:2);
            //
            RadioButton rb = new RadioButton();
            rb.ID = "rb" + rowid;
            rb.GroupName="rad";
            if (rowid == 0) rb.Checked = true;
            
            cell.Controls.Add(rb);
            row.Cells.Add(cell);//插入单元格

            //订单号
            cell = GetTableCell(width: 70);
            cell.Text = dr.ONO;
            row.Cells.Add(cell);

            //装货时间 ～ 卸货时间
            cell = GetTableCell(colspan: 5);
            cell.Text = dr.ZHUANGHUO_DATE + " " + dr.ZHUANGHUO_TIME + "～" + dr.XIEHUO_DATE + " " + dr.XIEHUO_TIME;
            row.Cells.Add(cell);

            //承运费
            cell = GetTableCell(colspan: 3);
            cell.Text = dr.CHENGYUN_COSTS.ToString();
            row.Cells.Add(cell);

            //押运单编号
            cell = GetTableCell(colspan: 3);
            cell.Text = dr.AGENTNO;
            row.Cells.Add(cell);

            //结算方式
            cell = GetTableCell(width: 58);
            cell.Text = dr.JIESUAN_TYPE_M;
            row.Cells.Add(cell);

            //订单状态
            cell = GetTableCell(width: 58);
            cell.Text = dr.ORDER_STATUS_M;
            row.Cells.Add(cell);

            //代理店信息
            cell = GetTableCell(width: 170);
            cell.Text = dr.AGENT_LUOCHENG;
            row.Cells.Add(cell);

            //发货地信息
            cell = GetTableCell(width: 170);
            cell.Text = dr.ZHUANGHUO_LUOCHENG;
            row.Cells.Add(cell);

            //收货地信息
            cell = GetTableCell(width: 170);
            cell.Text = dr.XIEHUO_LUOCHENG;
            row.Cells.Add(cell);

            this.tblList.Rows.Add(row);

            //----------------------------------------------------
            row = new TableRow();
            if (rowid % 2 == 0) { row.CssClass = "odd"; } else { row.CssClass = "even"; }
            //品名
            cell = GetTableCell();
            cell.Text = dr.PINMING_M;
            row.Cells.Add(cell);

            //长
            cell = GetTableCell(width: 35);
            cell.Text = dr.LENGTH.ToString();
            row.Cells.Add(cell);

            //宽
            cell = GetTableCell(width: 35);
            cell.Text = dr.WIDTH.ToString();
            row.Cells.Add(cell);

            //高	
            cell = GetTableCell(width: 35);
            cell.Text = dr.HIGHTH.ToString();
            row.Cells.Add(cell);

            //车型
            cell = GetTableCell(width: 60);
            cell.Text = dr.CHELIANG_XINGTAI_M;
            row.Cells.Add(cell);

            //总重量
            cell = GetTableCell(width: 50);
            cell.Text = dr.WEIGHT.ToString();
            row.Cells.Add(cell);
            //总数量
            cell = GetTableCell(width: 59, colspan: 2);
            cell.Text = dr.COUNTS.ToString();
            row.Cells.Add(cell);

            //已发重量
            cell = GetTableCell(width: 59, colspan: 2);
            cell.Text = dr.FAHUO_WEIGHT.ToString();
            row.Cells.Add(cell);

            //已发数量
            cell = GetTableCell(width: 59, colspan: 2);
            cell.Text = dr.FAHUO_COUNTS.ToString();
            row.Cells.Add(cell);

            //未发重量
            cell = GetTableCell();
            cell.Text = dr.WEIFA_WEIGHT.ToString();
            row.Cells.Add(cell);
            //未发数量
            cell = GetTableCell();
            cell.Text = dr.WEIFA_COUNTS.ToString();
            row.Cells.Add(cell);
            //代理店信息 联系人|联系电话
            cell = GetTableCell();
            cell.Text = dr.AGENT_LIANXI_REN;
            row.Cells.Add(cell);
            //发货地信息 联系人|联系电话
            cell = GetTableCell();
            cell.Text = dr.ZHUANGHUO_LIANXI_REN;
            row.Cells.Add(cell);

            //收货地信息 联系人|联系电话
            cell = GetTableCell(width: 170);
            cell.Text = dr.XIEHUO_LIANXI_REN;
            row.Cells.Add(cell);
            this.tblList.Rows.Add(row);

            rowid++;

        }
        
    }

   /// <summary>
    /// 
    /// </summary>
    /// <param name="width"></param>
    /// <param name="rowspan"></param>
    /// <returns></returns>
    private TableCell GetTableCell(int width = -1, int rowspan = 1, int colspan = 1)
    {
        //创建单元格对象
        TableCell cell = new TableCell();
        if (width != -1) cell.Width = width;
        if (rowspan > 1) cell.RowSpan = rowspan;
        if (colspan > 1) cell.ColumnSpan = colspan;
        return cell;
    }

    /// <summary>
    /// 
    /// </summary>
    protected string _jsonDt = null;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn客户查询_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn品名查询_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn发货地查询_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn送货地查询_Click(object sender, EventArgs e)
    {

    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn取消_Click(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn上一页_Click(object sender, EventArgs e)
    {
        this.hidPageNo.Value = string.IsNullOrEmpty(this.hidPageNo.Value) ? "1" : (int.Parse(this.hidPageNo.Value) - 1).ToString();
        this.hidPageNo.Value = this.hidPageNo.Value == "0" ? "1" : this.hidPageNo.Value;
        this.btn执行_Click(sender, e);
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn下一页_Click(object sender, EventArgs e)
    {
        this.hidPageNo.Value = string.IsNullOrEmpty(this.hidPageNo.Value) ? "1" : (int.Parse(this.hidPageNo.Value)+1).ToString();

        this.btn执行_Click(sender, e);

    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn清除_Click(object sender, EventArgs e)
    {

    }
    protected void btn订单一览打印_Click(object sender, EventArgs e)
    {
        return;
    }
    protected void btn订单完了登记_Click(object sender, EventArgs e)
    {

    }
    protected void btn订单完了解除_Click(object sender, EventArgs e)
    {

    }

    protected void proc清空_Init(string str处理区分)
    {
        Label lblMsgCD = (Label)Master.FindControl("lblMsgCD");
        Label lblMsg = (Label)Master.FindControl("lblMsg");
        lblMsgCD.Text = "";
        lblMsg.Text = "";

        //控件的Enabled进行控制
        #region
        this.txt订单号.Text = string.Empty;
        this.txt装货时间_Day.Text = string.Empty;
        this.txt装货时间_Hour.Text = string.Empty;
        this.txt卸货时间_Day.Text = string.Empty;
        this.txt卸货时间_Hour.Text = string.Empty;
        this.txt订单状态CD.Text = string.Empty;
        this.txt订单状态.Text = string.Empty;
        this.txt客户CD.Text = string.Empty;
        this.txt客户.Text = string.Empty;
        this.txt付款方式CD.Text = string.Empty;
        this.txt付款方式.Text = string.Empty;
        this.txt品名CD.Text = string.Empty;
        this.txt品名.Text = string.Empty;
        this.txt所用车型CD.Text = string.Empty;
        this.txt所用车型.Text = string.Empty;
        this.txt起点省市CD.Text = string.Empty;
        this.txt起点省市.Text = string.Empty;
        this.txt发货地CD.Text = string.Empty;
        this.txt发货地.Text = string.Empty;
        this.txt终点省市CD.Text = string.Empty;
        this.txt终点省市.Text = string.Empty;
        this.txt送货地CD.Text = string.Empty;
        this.txt送货地.Text = string.Empty;


        #endregion

        //总件数
        this.txt总件数.Text = string.Empty;

        //数据表清空
        for (int i = this.tblList.Rows.Count - 1; i >= 1; i--)
        {
            this.tblList.Rows.RemoveAt(i);
        }

    }
}